#ifndef _STDINT_H
#include <stdint.h>
#endif

#ifndef _STDIO_H
#include <stdio.h>
#endif

#ifndef _STDINT_H
#include <stdint.h>
#endif

#ifndef _STDLIB_H
#include <stdlib.h>
#endif

#ifndef _NTH_LIB_H
#include <nth-lib.h>
#endif

int main(void){

	int error = 0;

	const uint32_t op_max = 0x10000;

	uint32_t numerator = 0;
	uint32_t denominator = 0;
	uint32_t quotient = 0;
	uint32_t remainder = 0;

	struct Nth_Division nth_division;

	uint32_t quotient_buffer = 0;
	uint32_t remainder_buffer = 0;

	nth_division.operand_one.number_length = sizeof(numerator);
	nth_division.operand_one.number_buffer = &numerator;

	nth_division.operand_two.number_length = sizeof(denominator);
	nth_division.operand_two.number_buffer = &denominator;

	nth_division.quotient.number_length = sizeof(quotient_buffer);
	nth_division.quotient.number_buffer = &quotient_buffer;

	nth_division.remainder.number_length = sizeof(remainder_buffer);
	nth_division.remainder.number_buffer = &remainder_buffer;

	numerator = 1;
	denominator = 1;

	while (denominator <= op_max){

		numerator = denominator;

		while (numerator <= op_max){

			quotient = numerator / denominator;
			remainder = numerator % denominator;

			quotient_buffer = 0;
			remainder_buffer = 0;

			error = Divide_Nth_Numbers(&nth_division);

			if (error){

				fprintf(
					stderr,
					"%s: %s %u / %u\n",
					"main",
					"Division error occured",
					numerator,
					denominator
				);

				break;
			}

			if ((quotient_buffer != quotient)
			 || (remainder_buffer != remainder)){

				fputc('\n', stderr);

				fprintf(stderr, "   %u\n", numerator);
				fprintf(stderr, " / %u\n", denominator);
				fprintf(stderr, " = %u (%u)\n", quotient, remainder);
				fprintf(stderr, "!= %u (%u)\n", quotient_buffer, remainder_buffer);

				fputc('\n', stderr);

				error = 1;
				break;
			}

			numerator++;
		}

		if (error)
			break;

		denominator++;
	}

	if (error)
		return 1;

	return 0;
}

